//
//  AddressBookTableviewCell.m
//  TabBar
//
//  Created by 陈德锋 on 16/4/13.
//  Copyright © 2016年 陈德锋. All rights reserved.
//

#import "AddressBookTableviewCell.h"

@implementation AddressBookTableviewCell

+ (instancetype)AddressBookTableViewCellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"AddressBookTableviewCell";
    AddressBookTableviewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[AddressBookTableviewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        UIView * _line = [[UIView alloc] initWithFrame:CGRectMake(60, 60-0.5, [UIScreen mainScreen].bounds.size.width-60, 0.5)];
        _line.backgroundColor = [UIColor colorWithRed:220/255.0 green:220/255.0 blue:220/255.0 alpha:1];
        [self.contentView addSubview:_line];
        
    }
    return self;
}

- (void)setMember:(Member *)member
{
    _member = member;
    if (_member) {
        self.name.text = _member.name;
        self.name.textColor=[UIColor blackColor];
        
        self.intro.text = _member.intro;
        
        NSString *imageName = [NSString stringWithFormat:@"%@.jpg",_member.icon];
        self.icon.image = [UIImage imageNamed:imageName];
        
        NSString *imageName1 = [NSString stringWithFormat:@"%@",_member.vip];
        self.position.image = [UIImage imageNamed:imageName1];
        
    }
}

- (void)layoutSubviews{
    [super layoutSubviews];
    CGFloat space = 5.0;
    CGFloat cellW = self.contentView.frame.size.width;
    CGFloat cellH = self.contentView.frame.size.height;
    CGFloat iconW = cellH-space*2;
    
    self.icon.frame = CGRectMake(space, space, iconW, iconW);
    self.name.frame = CGRectMake(CGRectGetMaxX(self.icon.frame)+20, space+10, cellW/2.5, iconW/2.0);
    self.position.frame = CGRectMake(CGRectGetMaxX(self.name.frame)-70, space+15, cellW/10.0, iconW/4.0);

}

- (UILabel *)name{
    if (!_name) {
        _name = [[UILabel alloc]init];
        _name.font = [UIFont systemFontOfSize:18.0];
        _name.textAlignment = NSTextAlignmentLeft;
        _name.textColor = [UIColor blackColor];
        [self.contentView addSubview:_name];
    }
    return _name;
}

- (UIImageView *)icon{
    if (!_icon) {
        _icon = [[UIImageView alloc] init];
        _icon.image = [UIImage imageNamed:@""];
        [self.contentView addSubview:_icon];
    }
    return _icon;
}


- (UIImageView *)position{
    if (!_position) {
        _position = [[UIImageView alloc] init];
        _position.image = [UIImage imageNamed:@""];
        [self.contentView addSubview:_position];
    }
    return _position;
}


@end
